package com.zlm.linked;

/**
 * @author zlm
 * @date 2025/4/28
 *
 * 二级制转十进制
 */
public class Solution {

    public static void main(String[] args) {
        Node<Integer> head = new Node<>(0, null);
        head.next = new Node<>(0, null);
        //head.next.next = new Node<>(1, null);
        //head.next.next.next = new Node<>(0, null);
        System.out.println(binaryToDecimal(head));


    }

    /**
     * 二进制转十进制
     * @param head
     * @return
     */
    public static int binaryToDecimal(Node<Integer> head) {
        if(head == null){
            return 0;
        }
        //定义操作节点指针变量
        int res = head.value;
        Node<Integer> cur = head.next;

        while (cur != null){
            res = res * 2 + cur.value;
            cur = cur.next;
        }

        return res;
    }

}
